package net.hancl.modules.sys.controller.converter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HandlerExceptionResolverImp implements HandlerExceptionResolver {

    static Logger logger = LoggerFactory.getLogger(HandlerExceptionResolverImp.class);

    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
                                         Exception ex) {
        ex.printStackTrace();
        logger.error(ex.getMessage());
        // 根据不同错误转向不同页面
        if (ex instanceof org.apache.shiro.authz.AuthorizationException) {
            return new ModelAndView("/unauthorized");
        } else if (ex instanceof org.apache.shiro.authz.AuthorizationException) {
            return new ModelAndView("/unauthorized");
        } else {
            return new ModelAndView("/exception");
        }
    }

}
